class Solution {
public:
    vector<int> ret;
    int Max = 1;
    TreeNode* pre = NULL;
    int sum = 0;
    void sb(TreeNode* root){
        if(root == NULL) return;
        sb(root->left);
        
        if(pre == NULL){
            sum = 1;
        }else if(root->val == pre->val){
            sum++;
        }else{
            sum = 1;
        }
        pre = root;
        
        if(sum == Max){
            ret.push_back(root->val);
        }else if(sum > Max){
            Max = sum;
            ret.clear();
            ret.push_back(root->val);
        }
        
        sb(root->right);
    }
    vector<int> findMode(TreeNode* root) {
        sb(root);
        return ret;
    }
};
